-
Notifications
You must be signed in to change notification settings - Fork 44
Sphinx - Salma Anany #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on task-list-api!
app/sql/__init__.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this directory used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created it thinking I could add all the database querying functions and make the code dry, but sadly, I did not have enough time.
from app.models.task import Task | ||
|
||
goal_bp = Blueprint("goal_bp", __name__, url_prefix="/goals") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Learn and in the livecode for Flasky, we name blueprints for each model bp
. In goal_routes.py
I can deduce that bp
is the blueprint for Goal
given the name of the file.
If we have multiple route files that each have a blueprint named bp
, we can account for name collisions when importing them into app/__init__.py
by using aliases:
from .routes.task_routes import bp as tasks_bp
from .routes.goal_routes import bp as goals_bp
app/models/goal.py
Outdated
class Goal(db.Model): | ||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) | ||
title: Mapped[str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider whether the this column for Goal should be nullable. It feels odd to allow someone to create a goal that gets saved to the DB without a title.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is not Nullable, right?
app/models/goal.py
Outdated
title: Mapped[str] | ||
tasks = relationship('Task', back_populates='goal', cascade='all, delete-orphan') | ||
|
||
def to_dict(self, noTasks=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use snake case for variables in python
def to_dict(self, noTasks=True): | |
def to_dict(self, no_tasks=True): |
app/models/goal.py
Outdated
"goal_id": task.goal_id, | ||
"title": task.title, | ||
"description": task.description, | ||
"is_complete": task.completed_at is not None}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also put this logic in a helper function like is_complete
"is_complete": task.completed_at is not None}) | |
"is_complete": task.is_complete()}) |
|
||
notification_messages = SlackMessage("task-notifications", task_text) | ||
notification_was_sent = slack_client.post_message(notification_messages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~~Recall that the project requirement was to use the Python package requests
to make 3rd party API calls.
We want folks to get practice using requests
and not use the SlackClient
because not all 3rd party APIs wil provide you with a custom client.
@SalmaAnany Please let me know, as a repy to this comment, how you would re-write the code for calling Slack using requests
.~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used requests, please check the client, that's my own class using requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I meant to remove this comment after I saw your SlackClient class! Thanks for pointing me there again.
|
||
def change_task_status(task_id, is_completed): | ||
task = Task.query.get(task_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The <model>.query
syntax has been deprecated since SQLAlchemy 2.0 and should not be used for new development. This needs to removed to use the newer syntax:
query = db.select(Task).where(Task.id == task_id)
model = db.session.scalar(query)
See how we made a generic helper method for validating and fetching records from the DB in Flasky here on lines 10-11
Co-authored-by: Ashley Yang <[email protected]>
Co-authored-by: Ashley Yang <[email protected]>
No description provided.